package com.wc.acwing.思维.农夫约翰真的种地;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2025/2/27 21:51
 * @description
 * https://www.acwing.com/problem/content/5442/
 */
public class Main {
    /**
     * 视频教学：https://www.acwing.com/video/5544/
     * 思路：
     * 不等式求交集
     * 排列的以及就是正整数排列
     * t[i] 相当于 过了 x 天 有 t[i]个比自己高的, 自己的第 x 天的排序是 rk[t[i] + 1] = i
     * 第 x 天
     * h[rk[i]] + x * a[rk[i]] > h[rk[i + 1]] + x * a[rk[i + 1]]
     * => h[rk[i]] - h[rk[i + 1]] > x * (a[rk[i + 1]] - a[rk[i]])
     * A = h[rk[i]] - h[rk[i + 1]], B = (a[rk[i + 1]] - a[rk[i]])
     * 当 B > 0, x < A / B, x < A / B 上取整 - 1
     * 当 B < 0, x > A / B, x > A / B 下取整 + 1
     * 当 B = 0, A > 0 恒成立, A <= 0 无解
     * 注意 -5 / 2 = -3, 但是Java中 -5 / 2 = -2, 所以要使用 math里面额库函数 floor, ceil
     * 致辞结束
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 200010;
    static int[] h = new int[N], a = new int[N], rk = new int[N];
    static int n;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextInt();
            for (int i = 1; i <= n; i++) h[i] = sc.nextInt();
            for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
            for (int i = 1; i <= n; i++) {
                int t = sc.nextInt();
                // rk[i] 表示 i 的排名从高到底 是rk[i]
                rk[t + 1] = i;
            }
            int l = 0, r = (int)1e9;

            for (int i = 1; i < n; i++) {
                int A = h[rk[i]] - h[rk[i + 1]], B = a[rk[i + 1]] - a[rk[i]];
                if (B > 0) r = Math.min(r, (int)Math.ceil(A * 1.0 / B) - 1);
                else if (B < 0) l = Math.max(l, (int)Math.floor(A * 1.0 / B) + 1);
                else {
                    if (A <= 0) {
                        r = -1;
                        break;
                    }
                }
            }
            if (l > r) l = -1;
            // 求最小的天数
            out.println(l);
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}

